package com.world.business.dict.controller;

import com.world.business.dict.domain.DictType;
import com.world.business.dict.domain.query.DictGetTreeRequest;
import com.world.business.dict.domain.query.DictTypeAddRequest;
import com.world.business.dict.domain.vo.DictTreeVO;
import com.world.business.dict.service.IDictTypeService;
import com.world.common.controller.BaseController;
import com.world.common.domain.ResponseData;
import com.world.common.domain.SuccessResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 数据字典类型 前端控制器
 * </p>
 *
 * @author 邓驴
 * @since 2023-07-27
 */
@Api(tags = "数据字典类型")
@RestController
@RequestMapping("/dict/type")
public class DictTypeController extends BaseController<DictType> {

    @Resource
    private IDictTypeService dictTypeService;

    /**
     * 新增
     *
     * @param request 请求参数
     * @return {@link ResponseData <Long>} 数据字典类型Id
     * @author WangYX
     * @date 2023/07/28 11:03
     */
    @ApiOperation("新增")
    @PostMapping("/add")
    public ResponseData<Long> add(@Validated @RequestBody DictTypeAddRequest request) {
        return new SuccessResponseData<>(dictTypeService.add(request));
    }

    /**
     * 数据字典-树形结构
     *
     * @return {@link ResponseData}
     * @author WangYX
     * @date 2023/07/28 11:32
     */
    @ApiModelProperty("数据字典-树形结构")
    @GetMapping("/tree")
    public ResponseData<List<DictTreeVO>> tree(@RequestBody DictGetTreeRequest request) {
        List<DictTreeVO> tree = dictTypeService.tree(request);
        return new SuccessResponseData<>(tree);
    }

    /**
     * 详情
     *
     * @param id 字典类型Id
     * @return {@link ResponseData}
     * @author WangYX
     * @date 2023/07/28 14:02
     */
    @ApiOperation("详情")
    @GetMapping("/{id}")
    public ResponseData<DictTreeVO> get(@PathVariable("id") Long id) {
        return new SuccessResponseData<>(dictTypeService.get(id));
    }

    /**
     * 删除
     *
     * @param id 字典类型Id
     * @return {@link ResponseData}
     * @author WangYX
     * @date 2023/07/28 14:18
     */
    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ResponseData<Void> delete(@PathVariable("id") Long id) {
        dictTypeService.delete(id);
        return new SuccessResponseData<>();
    }


}
